package com.zonski.jbots.game.entity;

import com.zonski.jbots.engine.Rectangle;
import com.zonski.jbots.engine.Entity;
import com.zonski.jbots.engine.Engine;
import com.zonski.jbots.engine.entity.AbstractMind;
import com.zonski.jbots.engine.entity.Mind;

import com.zonski.jbots.game.JBotsConstants;

/**
 * class that literally explodes (expands) an object until it
 * dies, typically used in explosions
 */
public class ExplosionMind extends AbstractMind
{
    public static final int DEFAULT_INC  = 6;
    public static final int DEFAULT_MAX_UPDATE = 12*3 / DEFAULT_INC;

    private int inc = DEFAULT_INC;
    private int maxUpdate = DEFAULT_MAX_UPDATE;

    public ExplosionMind()
    {
    }

    public void update(Engine engine)
    {
        Entity entity = getEntity();
        int updates = getEntity().getEffectiveModeUpdates();
        // adjust the size
        if(updates == 1)
        {
            // shake it all about
            this.getEntity().getDevice().vibrate(this.maxUpdate);
            this.getEntity().getDevice().play(JBotsConstants.EXPLOSION, 1);
        }
        if(updates < maxUpdate)
        {
            Rectangle bounds = entity.bounds;
            int cx = bounds.getCentreX();
            int cy = bounds.getCentreY();
            int w = updates * inc;
            bounds.setCentre(cx, cy, w, w);
        }else{
            entity.setRemovable(true);
        }
    }

    public final int getMaxUpdates()
    {
        return this.maxUpdate;
    }

    public Mind copy()
    {
        return new ExplosionMind();
    }
}
